package com.ztt.controller.admin;


import com.ztt.pojo.entity.zttProduct;
import com.ztt.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/SelectAllProduct")
    public List<zttProduct> SelectAllProduct(){
        return productService.SelectAllProduct();
    };

    @PostMapping("/InsertProduct")
    public String InsertProduct(@RequestBody zttProduct product){
        productService.InsertProduct(product);
        return "success";
    };

    @PostMapping("/getProductById")
    public zttProduct getProductById(@RequestBody zttProduct product) {
        return productService.getProductById(product);
    }

    @PostMapping("/getProductByName")
    public zttProduct getProductByName(@RequestBody zttProduct product){
        return productService.getProductByName(product);
    }

    @PostMapping("/UpdateProduct")
    public  String UpdateProduct(@RequestBody zttProduct product){
        productService.UpdateProduct(product);
        return "success";
    }

    @PostMapping("/DeleteProduct")
    public  String DeleteProduct(@RequestBody zttProduct product) {
        try {

            productService.DeleteProduct(product);
            return "success";
        } catch (Exception e) {
            return "fail";

        }
    }

}
